<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="padding-top:25px">登录</header>
    <img src="../image/login.png" style="width:100%">
    <div class="login-form vue">
        <div class="form-item">
            <span class="label">手机号</span>
            <input type="tel" maxlength="11" v-model="form.mobile">
            <span class="input-clear" v-show="form.mobile" @click="clearMobile"></span>
        </div>
        <div class="form-item">
            <span class="label">密码</span>
            <input type="password" v-model="form.password">
            <span class="input-clear" v-show="form.password" @click="clearPassword"></span>
        </div>
        <div class="aui-btn-default" @click="login">登录</div>
        <div class="aui-row" style="text-align:center;margin-top:1rem;color:#fe4445;">
            <!-- <div class="aui-col-xs-6" @click="forget">忘记密码？</div>
            <div class="aui-col-xs-6" @click="register">立即注册</div> -->
        </div>
    </div>

    <script type="text/javascript" src="../script/vue.js"></script>
    <script type="text/javascript" src="../script/base64.js"></script>
    <script type="text/javascript" src="../script/app.js"></script>
    <script type="text/javascript">
        apiready = function() {
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                api.toLauncher();
                return false;
            });

            var Ve = new Vue({
                el: '.vue',
                data: {
                    form: {
                        mobile: '',
                        password: ''
                    }
                },
                methods: {
                    clearMobile: function() {
                        this.form.mobile = ''
                    },
                    clearPassword: function() {
                        this.form.password = ''
                    },
                    login: function() {
                        app.request.post('/myhome/login', {
                            user_name: this.form.mobile,
                            password: this.form.password,
                            signature: app.sign(this.form.mobile)
                        }, {}, function(res) {
                            // console.log(JSON.stringify(res))
                            if (res.code == 1) {
                                //登录成功
                                // {
                                //   "user_name":"13657085273",
                                //   "shop_qrcode":"http://mall.jxqkw8.com/upload/shop_qrcode/shop_qrcode_37.png",
                                //   "business_id":"37",
                                //   "customerCode":"15170123175",
                                //   "type_name":"餐饮"
                                // }
                                if (api.systemType == 'android') {
                                    var ajpush = api.require('ajpush');
                                    ajpush.init(function(ret) {
                                        if (ret && ret.status) {

                                            var alias = 'business_id_' + res.data.business_id
                                            ajpush.bindAliasAndTags({
                                                alias: alias
                                            });

                                            // console.log(alias)

                                            api.setPrefs({
                                                key: 'user',
                                                value: res.data
                                            });
                                            api.openWin({
                                                name: 'main',
                                                url: 'main.html',
                                                slidBackEnabled: false
                                            });
                                            setTimeout(function() {
                                                api.closeWin();
                                            }, 1000)

                                        }
                                    });
                                }
                            } else {
                                app.error(res.msg)
                            }
                        })
                    },
                    forget: function() {

                    },
                    register: function() {

                    }
                }
            })
        }
    </script>
</body>

</html>
